#include <iostream>
#include <string>
#include <unordered_map>

bool is_prime(int n) {
    if (n <= 1) {
        return false;
    }
    for (int i = 2; i <= static_cast<int>(sqrt(n)) + 1; i++) {
        if (n % i == 0) {
            return false;
        }
    }
    return true;
}

int closest_prime(int num) {
    int offset = 0;
    while (true) {
        if (is_prime(num - offset)) {
            return num - offset;
        } else if (is_prime(num + offset)) {
            return num + offset;
        }
        offset++;
    }
}

std::unordered_map<std::string, int> words_to_numbers = {
    {"zero", 0}, {"one", 1}, {"two", 2}, {"three", 3}, {"four", 4},
    {"five", 5}, {"six", 6}, {"seven", 7}, {"eight", 8}, {"nine", 9}
};

int words_to_num(std::string words) {
    try {
        std::string num_str;
        for (const std::string& word : words) {
            num_str += std::to_string(words_to_numbers[word]);
        }
        return std::stoi(num_str);
    } catch (...) {
        return -1; // Wrong input
    }
}

int main() {
    std::string input_words;
    std::cin >> input_words;
    int number = words_to_num(input_words);

    if (number != -1 && number >= 100 && number <= 999) {
        std::cout << closest_prime(number) << std::endl;
    } else {
        std::cout << "Wrong input" << std::endl;
    }

    return 0;
}
